package com.qgxy.putextra;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    private TextView tvAccount, tvPassword;
    private Button btnConfirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        tvAccount = findViewById(R.id.tv_account);
        tvPassword = findViewById(R.id.tv_password);
        btnConfirm = findViewById(R.id.btn_confirm);

        Intent intent = getIntent();
        String account = intent.getStringExtra("account");
        String password = intent.getStringExtra("password");
        tvAccount.setText(account);
        tvPassword.setText(password);

        btnConfirm.setOnClickListener(v -> {
            Intent intent1 = new Intent();
            intent1.putExtra("main_data", "接收到了账号和密码");
            setResult(2, intent1);
            finish();
        });
    }
}